package internet;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/*
    接受到数据并且，给出反馈
    代码用线程进行封装，为每一个客户端，开一个线程
* */
public class ServerDemo3 {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10001);

        //监听客户端
        Socket s = ss.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        BufferedWriter bw = new BufferedWriter(new FileWriter("funCode\\myNetCopy.txt"));

        String line;
        while ((line = br.readLine()) != null) {//等待读数据
            /*if ("886".equals(line)) {
                break;
            }*/
            bw.write(line);
            bw.newLine();
            bw.flush();
        }

        //给出反馈
        BufferedWriter bwS = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
        bwS.write("success");
        bwS.newLine();
        bwS.flush();


        bw.close();
        ss.close();
    }
}
